import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_boost/boost_navigator.dart';
import 'package:flutter_module/common/base/base_page.dart';
import 'package:flutter_module/common/utils/toast_utils.dart';
import 'package:flutter_module/page/base/base_view.dart';
import 'package:flutter_module/page/base/image_page.dart';
import 'package:flutter_module/style/colors.dart';

/// 合作服务商--banner
class ServiceProviderEditBannerPage extends BaseStateFulWidget {
  ServiceProviderEditBannerPage({required this.params});

  final int maxCount = 5;
  final Map params;

  @override
  BaseState<StatefulWidget> buildState() {
    return _ServiceProviderEditBannerState();
  }
}

class _ServiceProviderEditBannerState
    extends BaseState<ServiceProviderEditBannerPage> with BasePage {
  var imgList = <String>[];

  @override
  void initState() {
    imgList = widget.params["imgList"]??[];
    super.initState();
  }

  @override
  String get appBarTitle => "banner";

  @override
  getActions() {
    return [
      new TextClickView(
        title: "保存",
        isTitleRight: true,
        rightClick: () {
          BoostNavigator.instance.pop(imgList);
          print("dddd${imgList.length}");
        },
      )
    ];
  }

  @override
  Widget createView(
    BuildContext context,
  ) {
    return Container(
      color: Colors.white,
      padding: EdgeInsets.only(left: 16, top: 13, right: 16),
      child: ListView(
        shrinkWrap: true,
        children: <Widget>[
          Expanded(child: ImagePage(imgList, widget.maxCount)),
          _getAddButton(),
        ],
      ),
    );
  }

  _getAddButton() {
    return Container(
      height: 40,
      margin: EdgeInsets.only(top: 10, bottom: 40),
      decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(5),
          border: Border.all(color: ThemeColors.grayE5E5E5, width: 1)),
      child: InkWell(
        onTap: () {
          if (imgList.length >= widget.maxCount) {
            ToastUtils().showText("最多添加${widget.maxCount}张");
            return;
          }
          setState(() => imgList.add(""));
        },
        child: Container(
          color: Colors.white,
          alignment: Alignment.center,
          child: Text(
            "新增（最多添加${widget.maxCount}张）",
            style: TextStyle(color: ThemeColors.text888, fontSize: 14),
          ),
        ),
      ),
    );
  }


}
